package com.ymdx.filter;

import org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by yangliwei on 2017/8/12.
 */
public class UeditorFilter extends StrutsPrepareAndExecuteFilter {
    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        String url = request.getRequestURI();
//        System.out.println(url);
        if (url.contains("/ueditor/jsp/")) {
//            System.out.println("使用自定义过滤器");
            chain.doFilter(req, res);
        } else if (url.contains(".html")) {
            req.getRequestDispatcher(url).forward(req,res);
        } else {
//            System.out.println("使用默认过滤器");
            super.doFilter(req, res, chain);
        }
    }
}